﻿
using TouchSocket.Core;
using TouchSocket.Http;
using TouchSocket.Http.WebSockets;
using TouchSocket.Sockets;

namespace WebSocketServer.WebSocketService.Plugins
{
   

    public class MyWebSocketConnectionPlugin : PluginBase,
        IWebSocketHandshakedPlugin,
        IWebSocketClosedPlugin
       
    {
        private readonly ILog _logger;

        public MyWebSocketConnectionPlugin(ILog logger)
        {
            _logger = logger; // 也可以从 DI 注入一个 ILogger
        }

        public Task OnWebSocketHandshaked(IWebSocket webSocket, HttpContextEventArgs e)
        {
            _logger.Info($"[连接建立] 来自 {webSocket.Client.IP}");
            return Task.CompletedTask;
        }

     

        public Task OnWebSocketClosed(IWebSocket webSocket, ClosedEventArgs e)
        {
            _logger.Info($"[断开连接] 来自 {webSocket.Client.IP}");
            return Task.CompletedTask;
        }
    }

}
